package cn.cdiothree.controller;


import cn.cdiothree.dataobject.ProductCollect;
import cn.cdiothree.service.ProductCollectService;
import cn.cdiothree.vo.ProductCollectVO;
import cn.cdiothree.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/product-info")
public class ProductCollectController {
    @Autowired
    ProductCollectService productCollectService;

    /**
     * 添加收藏
     * @param productId
     * @param userId
     * @return
     */
    @GetMapping("/add/collect")
    public ResultVO addCollect(@RequestParam("productId") Integer productId,
                               @RequestParam("userId") Integer userId){
        ResultVO productCollect=productCollectService.addOrCancelCollect(productId,userId);
        return ResultVO.success(productCollect);
    }

    /**
     * 查看收藏状态
     * @param productId
     * @param userId
     * @return
     */
    @GetMapping("/collect")
    public ResultVO collect(@RequestParam("productId")Integer productId,
                            @RequestParam("userId") Integer userId){
        ProductCollect productCollect = productCollectService.selectByProductIdAndUserId(productId,userId);
        return ResultVO.success(productCollect);
    }

    @GetMapping("/list")
    public List<ProductCollectVO> list(Integer userId){
        List<ProductCollectVO> productCollectVOList = productCollectService.list(userId);
        return productCollectVOList;
    }
}
